// 引入依赖的配置文件模块
require(["config"], function(){
	// 引入依赖模块
	require(["jquery","template","header","carousel"], function($,template){
		function Index(){
			this.render();
			this.loadCarousel();
		}
		
		$.extend(Index.prototype,{
			//渲染详情页面数据
			render:function(){
				$.ajax("http://rap2api.taobao.org/app/mock/86896/wangyi/index")
					.done($.proxy(this.handleData,this));
			},
			//处理ajax获取到的数据
			handleData:function(data){
				//获取使用数据
				var news={list:data.res_body.new};
				var limits={limit:data.res_body.limit,bigimage:data.res_body.bigimage};
				var todays={today:data.res_body.today};
				var brand={brandimage:data.res_body.brandimage,brand:data.res_body.brand};
				var baby={babyimage:data.res_body.babyimage,middle:data.res_body.middle,small:data.res_body.small};
				var sell={sell:data.res_body.sell};
				var like={like:data.res_body.like};
//				console.log(limits);
//				console.log(news);
//				console.log(brand);
				//渲染
				var newsHtml=template("new_template",news);
				var limitHtml=template("limit_template",limits);
				var todayHtml=template("today_template",todays);
				var brandHtml=template("brand_template",brand);
				//7个baby
				var babyHtml=template("baby_template",baby);
				var sellHtml=template("sell_template",sell);
				//猜你喜欢
				var likeHtml=template("like_template",like);
				
				
				$("#docNew .new").html(newsHtml);
				$("#docLimit .bottom").html(limitHtml);
				$("#docNewProduct .bottom").html(todayHtml);
				$("#docBrand .bottom").html(brandHtml);
				//7个baby
				$("#docMotherArea .bottom").html(babyHtml);
				$("#docMotherArea .bestSellers").html(sellHtml);
				$("#docCosmetology .bottom").html(babyHtml);
				$("#docCosmetology .bestSellers").html(sellHtml);
				//猜你喜欢
				$("#docLike .like").html(likeHtml);
			},
			//加载轮播图
			loadCarousel:function(){
				$("#banner .carousel-box").carousel({
					imgs:[
						{href:"/html/list.html",src:"/images/banner11.jpg"},
						{href:"/html/list.html",src:"/images/banner22.jpg"},
						{href:"/html/list.html",src:"/images/banner33.jpg"},
						{href:"/html/list.html",src:"/images/banner44.jpg"},
						{href:"/html/list.html",src:"/images/banner55.jpg"},
						{href:"/html/list.html",src:"/images/banner66.jpg"}
					],
					width:"100%",
					height:465,
					duration:3000
				});
			}
			//放入与移开
			
		});
		
		new Index();
	});
});